from django import template
from django.conf import settings
from django.utils.html import escape
from django.utils.translation import get_language

from cms.models import Page
from cms.cms_global_settings import *

register = template.Library()

class CmsFrontPageNavigation(template.Node):
    def __init__(self, varname):
        self.varname = varname

    def render(self, context):
        pages = Page.objects.filter(parent__isnull=True,in_navigation=True)
        pages = Page.objects.filter(parent=pages[0], in_navigation=True)
        context[self.varname] = pages
        return ''

def cms_frontpage_navigation(parser, token):
    tokens = token.contents.split()
    if len(tokens) != 3:
        raise template.TemplateSyntaxError, "'%s' tag requires two arguments" % tokens[0]
    if tokens[1] != 'as':
        raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % tokens[0]
    return CmsFrontPageNavigation(tokens[2])
cms_frontpage_navigation = register.tag(cms_frontpage_navigation)
